package com.ita.iosc.util;

import java.sql.Connection;
import java.sql.SQLException;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

public class DbConnection {
	
	private static DbConnection connection = new DbConnection();
	private static BasicDataSource dataSource;
	
	public DbConnection () {
		BasicDataSource dataSource = new BasicDataSource();
		dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
		dataSource.setUrl("jdbc:oracle:thin:@ZHA-ITA129-W7.corp.oocl.com:1521:xe");
		dataSource.setUsername("book_db_1");
		dataSource.setPassword("123456");
		this.dataSource = dataSource;
	}
	
	public static Connection getConnection() throws SQLException {
		return dataSource.getConnection();
	}
	
	public static void free() throws SQLException{
		dataSource.close();
	}
	
	public static void close(Connection connection) {
		try {
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
